package com.jzo2o.market.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.market.model.dto.request.ActivityQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.ActivitySaveReqDTO;
import com.jzo2o.market.model.dto.response.ActivityInfoResDTO;
import com.jzo2o.market.service.IActivityService;
import com.jzo2o.mysql.utils.PageUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 活动相关接口
 *
 * @Author yzx
 * @Date 2024/12/15 20:38
 */
@RestController
@RequestMapping("/operation/activity")
public class ActivityController {
    @Resource
    private IActivityService activityService;

    @PostMapping("/save")
    public void saveOrUpdate(@RequestBody ActivitySaveReqDTO activitySaveReqDTO){
        activityService.saveOrUpdate(activitySaveReqDTO);
    }
    @GetMapping("/page")
    public PageResult<ActivityInfoResDTO> pageQuery(ActivityQueryForPageReqDTO dto){
        return PageUtils.toPage(activityService.pageQuery(dto), ActivityInfoResDTO.class);
    }
    @GetMapping("/{id}")
    public ActivityInfoResDTO getById(@PathVariable Long id){

        return BeanUtils.toBean(activityService.getById(id), ActivityInfoResDTO.class);
    }

    @PostMapping("revoke/{id}")
    public void revoke(@PathVariable Long id){
        activityService.revoke(id);
    }


}
